package com.example.idachuappone.activie;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.support.v4.view.accessibility.AccessibilityNodeInfoCompat;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;

import com.example.idachuappone.BaseActivity;
import com.example.idachuappone.LoadingActivity;
import com.example.idachuappone.MainTWo;
import com.example.idachuappone.R;
import com.example.idachuappone.utils.BitmapUtilHelper;
import com.lidroid.xutils.BitmapUtils;
import com.lidroid.xutils.bitmap.BitmapGlobalConfig.BitmapCacheManagementTask;

public class ActiveActivity extends BaseActivity {
	private Animation animation;
	private BitmapUtils bu;
	private Handler handler;
	private ImageView img;
	private Runnable runnable;

	public ActiveActivity() {
		this.handler = new Handler();
		this.runnable = new Runnable() {
			@Override
			public void run() {
				ActiveActivity.this.img.startAnimation(ActiveActivity.this.animation);
			}
		};
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_active);
		getWindow().setFlags(AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT,
				AccessibilityNodeInfoCompat.ACTION_NEXT_HTML_ELEMENT);
		this.bu = BitmapUtilHelper.createBitmapUtil(this);
		initView();
	}

	private void initView() {
		this.img = (ImageView) findViewById(R.id.img);
		this.bu.display(this.img, LoadingActivity.welcome.getFlash());
		this.animation = AnimationUtils.loadAnimation(this, R.anim.start_page_in_out);
		this.animation.setFillAfter(true);
		this.animation.setAnimationListener(new AnimationListener() {
			@Override
			public void onAnimationStart(Animation animation) {
			}

			@Override
			public void onAnimationRepeat(Animation animation) {
			}

			@Override
			public void onAnimationEnd(Animation animation) {
				ActiveActivity.this.img.setVisibility(BitmapCacheManagementTask.MESSAGE_CLEAR_MEMORY_BY_KEY);
				ActiveActivity.this.startActivity(new Intent(ActiveActivity.this, MainTWo.class));
			}
		});
		this.handler.postDelayed(this.runnable, 2000);
	}
}
